<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作业</title>
</head>
<body>
<div>
    <input type="text" v-model="info" placeholder="请输入1-100之间的整数">
    <input type="button" value="猜一猜" @click="f()">
    <h3>{{result}}</h3>
</div>
<!--引入vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    //得到1-100随机数
    let x = parseInt(Math.random()*100)+1;
    let count = 0;
    let v = new Vue({
        el:"div",
        data:{
            info:"",//得到用户输入内容需要双向绑定
            result:""
        },
        methods:{
            f:function () {
                if(isNaN(v.info)){
                    v.result="输入错误";
                    return;
                }
                count++;
                //v.info代表用户输入的内容
                if(v.info>x){
                    v.result="猜大了";
                }else if (v.info<x){
                    v.result="猜小了";
                }else{
                    v.result="恭喜你第"+count+"次猜对了";
                }

            }
        }
    })
</script>
</body>
</html>